(function()
{
    var agent = navigator.userAgent.toLowerCase();        //检测是否是ios
    var iLastTouch = null;                                //缓存上一次tap的时间
    if (agent.indexOf('iphone') >= 0 || agent.indexOf('ipad') >= 0)
    {
        document.addEventListener('touchend', function(event)
        {
            var iNow = new Date().getTime();
            iLastTouch = iLastTouch || iNow + 1 /** 第一次时将iLastTouch设为当前时间+1 */ ;
            var delta = iNow - iLastTouch
            if (delta < 500 && delta > 0)
            {
                event.preventDefault();
                return false;
            }
            iLastTouch = iNow;
        }, false);
    }

})();
(function(win, doc) {
    function SetFun() {

    };
    SetFun.prototype = {
        getParam: function(paramName) {
            paramValue = "", isFound = !1;
            if (win.location.search.indexOf("?") == 0 && win.location.search.indexOf("=") > 1) {
                arrSource = unescape(win.location.search).substring(1, win.location.search.length).split("&"), i = 0;
                while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
            }
            return paramValue == "" && (paramValue = null), paramValue
        },
        getToken: function(code,callback){
            var _self = this;
            axios.get('http://airen.2020-2020.com/v1/token/wechat/mp?code=' + code + '&appid=wx32726bfb51bf1d44')
                .then(function(response) {
                    var token = response.data.data.access_token;
                    localStorage.setItem('access_token',token);
                    if(callback){
                        callback();
                    }
                })
                .catch(function (error) {
                    console.log(error);
                });
        },
        goCodePage:function(){
             var url = window.location.href.split('#')[0];
                axios.get("http://airen.2020-2020.com/v1/token/wechat/mp?appid=wx32726bfb51bf1d44&redirect_uri=" + url + "&scope=userinfo")
                .then(function(data){
                    window.location.href =data.data.data;
                })
        },
        hideMenu:function(){
            const appid = "wx32726bfb51bf1d44";
            var url = window.location.href.split('#')[0];
            axios.get("http://airen.2020-2020.com/v1/token/js_sign?appid=" + appid + '&url=' + url)
            .then(function (response){
                wx.config(response.data.data);
            })
            wx.ready(function (){
                wx.hideOptionMenu();
            })
        },
        goShare:function(shareCode,params){
            const appid = "wx32726bfb51bf1d44";
            var  _self = this;
            var title = '爱仁医生';
            var desc = "爱仁眼健康服务平台";
            var imgUrl = "http://airen.2020-2020.com/m1/images/logo4.jpg";
            var url = 'http://airen.2020-2020.com/m1/index.html';
            if(shareCode){
                 url = 'http://airen.2020-2020.com/m1/get.html?shareCode=' + shareCode;
                 desc = "您有1000点的亮度，积攒亮度可换取眼科药品、更优惠的诊疗、三甲医院专家会诊等…🌞😊";
            }else{
                console.log(params.desc);
               desc = params.desc;
            }
            axios.get("http://airen.2020-2020.com/v1/token/js_sign?appid=" + appid + '&url=' + url)
            .then(function (response){
                wx.config(response.data.data);
            })
            var conf = {
                title: title, // 分享标题
                link: url, // 分享链接
                desc: desc,
                imgUrl: imgUrl, // 分享图标
                success: function (data) {
                },
                cancel: function (data) {
                }
            };
            wx.ready(function () {
                wx.onMenuShareTimeline(conf);
                wx.onMenuShareQZone(conf);
                wx.onMenuShareWeibo(conf);
                wx.onMenuShareQQ(conf);
                wx.onMenuShareAppMessage(conf);
            });
        },
        isCode:function(callback){
            var code = this.getParam('code');
            var  _self = this;
            if(code){
                if(callback){
                    _self.getToken(code,callback);
                }else{
                    _self.getToken(code);
                }
            }else{
                _self.goCodePage();
            }
        },
   
    }

    win.SetFun = SetFun;
})(window, document)